//
//  BalancerView.m
//  LINNER
//
//  Created by Kendama on 2017/10/11.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import "BalancerView.h"
#define ViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]
//#define greenColor [UIColor colorWithRed:28/255.0 green:167/255.0 blue:134/255.0 alpha:1]

@implementation BalancerView

#pragma mark -- 点击事件
- (void)didClickBalancerButton
{
    self.balancerButton.selected = YES;
    self.lowPitchButton.selected = NO;
    self.voiceButton.selected = NO;
    self.highPitchButton.selected = NO;
    
    [self.balancerButton setBackgroundColor:greenColor];
    [self.lowPitchButton setBackgroundColor:[UIColor whiteColor]];
    [self.voiceButton setBackgroundColor:[UIColor whiteColor]];
    [self.highPitchButton setBackgroundColor:[UIColor whiteColor]];
    
    self.balancerImageView.image = [UIImage imageNamed:@"bg_equilibrium"];

    if ([self.delegate respondsToSelector:@selector(balancerViewSelected:)])
    {
        [self.delegate balancerViewSelected:0];
    }
}

- (void)didClickLowPitchButton
{
    self.balancerButton.selected = NO;
    self.lowPitchButton.selected = YES;
    self.voiceButton.selected = NO;
    self.highPitchButton.selected = NO;
    
    [self.balancerButton setBackgroundColor:[UIColor whiteColor]];
    [self.lowPitchButton setBackgroundColor:greenColor];
    [self.voiceButton setBackgroundColor:[UIColor whiteColor]];
    [self.highPitchButton setBackgroundColor:[UIColor whiteColor]];
    
    self.balancerImageView.image = [UIImage imageNamed:@"bg_bass"];

    if ([self.delegate respondsToSelector:@selector(balancerViewSelected:)])
    {
        [self.delegate balancerViewSelected:1];
    }
}

- (void)didClickVoiceButton
{
    self.balancerButton.selected = NO;
    self.lowPitchButton.selected = NO;
    self.voiceButton.selected = YES;
    self.highPitchButton.selected = NO;
    
    [self.balancerButton setBackgroundColor:[UIColor whiteColor]];
    [self.lowPitchButton setBackgroundColor:[UIColor whiteColor]];
    [self.voiceButton setBackgroundColor:greenColor];
    [self.highPitchButton setBackgroundColor:[UIColor whiteColor]];
    
    self.balancerImageView.image = [UIImage imageNamed:@"bg_voice"];

    
    if ([self.delegate respondsToSelector:@selector(balancerViewSelected:)])
    {
        [self.delegate balancerViewSelected:2];
    }
}

- (void)didClickHighPitchButton
{
    self.balancerButton.selected = NO;
    self.lowPitchButton.selected = NO;
    self.voiceButton.selected = NO;
    self.highPitchButton.selected = YES;
    
    [self.balancerButton setBackgroundColor:[UIColor whiteColor]];
    [self.lowPitchButton setBackgroundColor:[UIColor whiteColor]];
    [self.voiceButton setBackgroundColor:[UIColor whiteColor]];
    [self.highPitchButton setBackgroundColor:greenColor];
    
    self.balancerImageView.image = [UIImage imageNamed:@"bg_treble"];
    
    if ([self.delegate respondsToSelector:@selector(balancerViewSelected:)])
    {
        [self.delegate balancerViewSelected:3];
    }
}


#pragma mark -- 事件处理
- (void)setBalancerViewSelected:(NSInteger)index
{
    switch (index) {
        case 0:
        {
            [self didClickBalancerButton];
        }
            break;
        case 1:
        {
            [self didClickLowPitchButton];
        }
            break;
        case 2:
        {
            [self didClickVoiceButton];
        }
            break;
        case 3:
        {
            [self didClickHighPitchButton];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark -- 懒加载
- (UIImageView *)balancerImageView
{
    if(!_balancerImageView)
    {
        UIView *superView = self;
        _balancerImageView = [[UIImageView alloc]init];
        [superView addSubview:_balancerImageView];
        _balancerImageView.image = [UIImage imageNamed:@"bg_equilibrium"];

    }
    return _balancerImageView;
}


- (UIButton *)balancerButton
{
    if(!_balancerButton)
    {
        UIView *superView = self;
        _balancerButton = [[UIButton alloc]init];
        [superView addSubview:_balancerButton];
        [_balancerButton setTitle:MyNSLocalizedString(@"均衡\n模式") forState:UIControlStateNormal];
        _balancerButton.titleLabel.numberOfLines = 2;
        _balancerButton.titleLabel.font = [UIFont systemFontOfSize:15];
        ViewBorderRadius(_balancerButton, px1920Height(100), 1, [UIColor colorWithRed:28/255.0 green:167/255.0 blue:134/255.0 alpha:1]);
        [_balancerButton setTitleColor:greenColor forState:UIControlStateNormal];
        [_balancerButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [_balancerButton addTarget:self action:@selector(didClickBalancerButton) forControlEvents:UIControlEventTouchUpInside];
        _balancerButton.selected = YES;
        [_balancerButton setBackgroundColor:greenColor];

    }
    return _balancerButton;
}

- (UIButton *)lowPitchButton
{
    if(!_lowPitchButton)
    {
        UIView *superView = self;
        _lowPitchButton = [[UIButton alloc]init];
        [superView addSubview:_lowPitchButton];
        [_lowPitchButton setTitle:MyNSLocalizedString(@"低音\n增强") forState:UIControlStateNormal];
        [_lowPitchButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
        _lowPitchButton.titleLabel.numberOfLines = 2;
        ViewBorderRadius(_lowPitchButton, px1920Height(100), 1, [UIColor colorWithRed:28/255.0 green:167/255.0 blue:134/255.0 alpha:1]);
        [_lowPitchButton setTitleColor:greenColor forState:UIControlStateNormal];
        [_lowPitchButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [_lowPitchButton addTarget:self action:@selector(didClickLowPitchButton) forControlEvents:UIControlEventTouchUpInside];

    }
    return _lowPitchButton;
}
- (UIButton *)voiceButton
{
    if(!_voiceButton)
    {
        UIView *superView = self;
        _voiceButton = [[UIButton alloc]init];
        [superView addSubview:_voiceButton];
        [_voiceButton setTitle:MyNSLocalizedString(@"人声\n增强") forState:UIControlStateNormal];
        [_voiceButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
        _voiceButton.titleLabel.numberOfLines = 2;
        ViewBorderRadius(_voiceButton, px1920Height(100), 1, [UIColor colorWithRed:28/255.0 green:167/255.0 blue:134/255.0 alpha:1]);
        [_voiceButton setTitleColor:greenColor forState:UIControlStateNormal];
        [_voiceButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [_voiceButton addTarget:self action:@selector(didClickVoiceButton) forControlEvents:UIControlEventTouchUpInside];

    }
    return _voiceButton;
}
- (UIButton *)highPitchButton
{
    if(!_highPitchButton)
    {
        UIView *superView = self;
        _highPitchButton = [[UIButton alloc]init];
        [superView addSubview:_highPitchButton];
        [_highPitchButton setTitle:MyNSLocalizedString(@"高音\n增强") forState:UIControlStateNormal];
        [_highPitchButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
        _highPitchButton.titleLabel.numberOfLines = 2;
        ViewBorderRadius(_highPitchButton, px1920Height(100), 1, [UIColor colorWithRed:28/255.0 green:167/255.0 blue:134/255.0 alpha:1]);
        [_highPitchButton setTitleColor:greenColor forState:UIControlStateNormal];
        [_highPitchButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [_highPitchButton addTarget:self action:@selector(didClickHighPitchButton) forControlEvents:UIControlEventTouchUpInside];

    }
    return _highPitchButton;
}



- (void)masLayoutSubview
{
    __weak UIView *superView = self;
    CGFloat buttonWidth = px1920Height(200);
    CGFloat place = (SCREEN_WIDTH - px1920Height(800))/5;
    
    [self.balancerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView.mas_top).with.offset(px1920Height(300));
        make.left.mas_equalTo(superView.mas_left).with.offset(px1080Width(65));
        make.right.mas_equalTo(superView.mas_right).with.offset(px1080Width(-65));
        make.height.mas_equalTo(px1920Height(710));
    }];
    
    [self.balancerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.balancerImageView.mas_bottom).with.offset(px1920Height(120));
        make.left.mas_equalTo(superView.mas_left).with.offset(place);
        make.width.height.mas_equalTo(buttonWidth);
    }];
    
    [self.lowPitchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.balancerImageView.mas_bottom).with.offset(px1920Height(120));
        make.left.mas_equalTo(self.balancerButton.mas_right).with.offset(place);
        make.width.height.mas_equalTo(buttonWidth);
    }];
    
    [self.voiceButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.balancerImageView.mas_bottom).with.offset(px1920Height(120));
        make.left.mas_equalTo(self.lowPitchButton.mas_right).with.offset(place);
        make.width.height.mas_equalTo(buttonWidth);
    }];
    
    [self.highPitchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.balancerImageView.mas_bottom).with.offset(px1920Height(120));
        make.left.mas_equalTo(self.voiceButton.mas_right).with.offset(place);
        make.width.height.mas_equalTo(buttonWidth);
    }];
}

@end
